package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysPaperConvert;
import net.learn.system.convert.SysRadioConvert;
import net.learn.system.convert.SysSubjectConvert;
import net.learn.system.dao.SysSubjectDao;
import net.learn.system.entity.SysPaperEntity;
import net.learn.system.entity.SysRadioEntity;
import net.learn.system.entity.SysSubjectEntity;
import net.learn.system.query.SysRadioQuery;
import net.learn.system.query.SysSubjectQuery;
import net.learn.system.service.SysSubjectService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysPaperVO;
import net.learn.system.vo.SysRadioVO;
import net.learn.system.vo.SysSubjectVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 李立志
 * @since 2022-04-01
 */
@Service
public class SysSubjectServiceImpl extends BaseServiceImpl<SysSubjectDao, SysSubjectEntity> implements SysSubjectService {
    @Override
    public Boolean addSubject(SysSubjectVO vo){
        SysSubjectEntity entity = SysSubjectConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        return baseMapper.insert(entity)>0;
    }
    @Override
    public Boolean updateSubject(SysSubjectVO vo){
        SysSubjectEntity entity = SysSubjectConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delVideoById(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysSubjectVO> qrySubjectList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<SysSubjectVO> qrySubjectListArray(SysSubjectQuery qry) {

        return baseMapper.qrySubjectListArray(qry);
    }
    @Override
    public PageResult<SysSubjectVO> qrySubjectListPage(SysSubjectQuery query) {
        IPage<SysSubjectEntity> page = baseMapper.qrySubjectListPage(getPage(query), query);

        return new PageResult<>(SysSubjectConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
